package com.ok.upload.controller;

import com.ok.common.domain.po.Result;
import com.ok.upload.utils.AliOSSUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
@Api(tags = "文件上传接口")
public class UploadController {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    @PostMapping("/upload")
    @ApiOperation(value = "文件上传")
    public Result<String> upload(@RequestPart("file") MultipartFile image) throws IOException {
        String url = aliOSSUtils.upload(image);
        log.info("文件上传：{}",image);
        return Result.success(url);
    }


}
